<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\EnrollTeacher;
use App\Models\UserAttribute;
use App\User;
class ModifyUserFissionInfo extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'modify:user_fission_info';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '修改老师属性信息，是否为裂变者';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $teachers = EnrollTeacher::select('mobile','name')->get();
        $i = 0;
        foreach($teachers as $teach){
            $user = User::where('mobile',$teach->mobile)->first();
            if(!$user){
                continue;
            }
            $userAttr = UserAttribute::where('user_id',$user->id)->first();
            if($userAttr->is_fission){
                continue;
            }else{
                $userAttr->is_fission = 1;
                if(!$userAttr->save()){
                    logger()->info('保存失败userid'.$user->id);
                }
            }
        }
        $this->info('完成');
    }
}
